package star.cloud.asme.base.security.authenticaiton;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import star.cloud.asme.base.dto.Result;
import star.cloud.asme.system.user.User;

@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@Slf4j
public class AuthenticationController {

    private final AuthenticationService authenticationService;

    @RequestMapping("/register")
    public Result<User> register(User user) {
        return authenticationService.registerUser(user);
    }

    @PostMapping("/login")
    public Result<User> login(User user) {
        return authenticationService.login(user);
    }

    @GetMapping("/logout/{username}")
    public Result<?> logout(@PathVariable("username") String username) {
        return authenticationService.logout(username);
    }

    @RequestMapping("/login/success")
    public Result<User> handleAuthenticateSuccess() {
        log.info("handleAuthenticateSuccess is running.........");
        return authenticationService.handleAuthenticateSuccess();
    }

    @RequestMapping("/login/fail")
    public Result<User> handleAuthenticateFail() {
        log.info("handleAuthenticateFail is running.........");
        return authenticationService.handleAuthenticateFail();
    }

    @RequestMapping("/logout/success")
    public String handleLogoutSuccess() {
        log.info("handleLogoutSuccess is running.........");
        return "注销成功";
    }

}